//package timing.ukulele.gateway.handler;
//
//import com.fasterxml.jackson.databind.ObjectMapper;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.http.HttpStatus;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.MediaType;
//import org.springframework.security.access.AccessDeniedException;
//import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler;
//import org.springframework.stereotype.Component;
//import timing.ukulele.common.data.ResponseVO;
//import timing.ukulele.common.exception.DefaultError;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.io.PrintWriter;
//
///**
// * 授权拒绝处理器，覆盖默认的OAuth2AccessDeniedHandler
// *
// * @author fengxici
// */
//@Slf4j
//@Component
//public final class UkuleleAccessDeniedHandler extends OAuth2AccessDeniedHandler {
//    private final ObjectMapper objectMapper;
//
//    @Autowired
//    public UkuleleAccessDeniedHandler(ObjectMapper objectMapper) {
//        this.objectMapper = objectMapper;
//    }
//
//    /**
//     * 授权拒绝处理，使用R包装
//     *
//     * @param request       request
//     * @param response      response
//     * @param authException authException
//     * @throws IOException IOException
//     */
//    @Override
//    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException authException) throws IOException, ServletException {
//        super.handle(request, response, authException);
//        log.info("授权失败，禁止访问 {}", request.getRequestURI());
//        response.setCharacterEncoding("UTF-8");
//        response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
//        ResponseVO<Object> result = ResponseVO.failure(DefaultError.ACCESS_DENIED);
//        response.setStatus(HttpStatus.SC_FORBIDDEN);
//        PrintWriter printWriter = response.getWriter();
//        printWriter.append(objectMapper.writeValueAsString(result));
//    }
//}
